/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dmcn.bl.genetics.input;

import au.com.bytecode.opencsv.CSVReader;
import dmcn.bl.genetics.execute.ExecuteGenetic;
import java.awt.Label;
import java.awt.TextField;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jgap.InvalidConfigurationException;

/**
 *
 * @author skyr
 */
public class NewMain {

    private static final String ADDRESS_FILE = "input.csv";
    private Input input;
    private TextField phgesText;
    private TextField sygkentrotesText;
    
    public NewMain() {
    }

    private void init() throws FileNotFoundException, IOException, InvalidConfigurationException {
        initInput();
        ExecuteGenetic eg = new ExecuteGenetic();
        eg.executeGenetic(
                input,//input object
                100,//population size
                100,//num of evolves
                true,//more options
                10,//mutation
                10, //crossover
                1,
                5000
                );
    }
    
//    private void initForm(){
//        JFrame jFrame = new JFrame("Genetic");
//        Label phgesLabel = new Label("phges");
//        phgesText = new TextField();
//        Label sygkentrotesLabel = new Label("sugkentrotes");
//        sygkentrotesText = new TextField();
//        JPanel panel = new JPanel();
//        panel.add(phgesLabel);
//        panel.add(phgesText);
//        panel
//    }

    private void initInput()  {
        try {
            CSVReader reader = new CSVReader(new FileReader(ADDRESS_FILE), ";".charAt(0));
            String[] nextLine = reader.readNext();
            Integer phges = Integer.parseInt(nextLine[0]);
            System.out.println("terminals: " + phges);
            nextLine = reader.readNext();
            Integer sygkentrotes = Integer.parseInt(nextLine[0]);
            System.out.println("concetrators: " + sygkentrotes);
            Integer[] fortio = new Integer[phges];
            Integer[] xwritikothta = new Integer[sygkentrotes];
            Integer[][] kostos = new Integer[sygkentrotes][phges];
            nextLine = reader.readNext();
            for (int i = 0; i < phges; i++) {
                fortio[i] = Integer.parseInt(nextLine[i]);
            }
            nextLine = reader.readNext();
            for (int i = 0; i < sygkentrotes; i++) {
                xwritikothta[i] = Integer.parseInt(nextLine[i]);
            }
            int i = 0;
            while ((nextLine = reader.readNext()) != null) {
                for (int j = 0; j < phges; j++) {
                    kostos[i][j] = Integer.parseInt(nextLine[j]);
                }
                i++;
            }
            input = new Input(phges, sygkentrotes, fortio, xwritikothta, kostos);
        } catch (IOException ex) {
            Logger.getLogger(NewMain.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        NewMain main = new NewMain();
        main.init();
    }
}
